<template>
  <div class="container with-nav-padding">
    <div class="addr-list">
      <div v-for="item in addrList" class="addr-cell">
        <div @click="chooseAddr(item)" class="addr-info">
          <div class="user">
            <span class="name">{{ item.realname }}</span>
            <span class="tel">{{ item.mobile }}</span>
          </div>
          <div class="addr">
            <span v-if="item.is_default" class="default">默认</span>
            {{ item.city_str }} {{ item.detail }}
          </div>
        </div>
        <button
          class="edit"
          @click="
            $router.push({
              path: '/address',
              query: {
                addrId: item.id
              }
            })
          "
        >
          编辑
        </button>
      </div>
    </div>
    <button
      @click="$router.push({ path: '/address' })"
      class="bottom-btn"
      :class="{ 'fullscreen-margin': isFullscreen }"
      :style="{background: mainColor}"
    >
      <img src="@/assets/我的收货地址-assets/添加1.png" alt="" /> 添加新地址
    </button>
  </div>
</template>

<script>
import { getAddrList } from "@/api/profile";
import { mapMutations } from "vuex";
import { mapState } from "vuex";
export default {
  data() {
    return {
      addrList: []
    };
  },
  computed: {
    ...mapState({
      isFullscreen: state => state.app.isFullscreen,
      mainColor: state => state.app.mainColor,
      subColor: state => state.app.subColor
    })
  },
  methods: {
    ...mapMutations(["setAddr"]),
    chooseAddr(addr) {
      if (this.$route.query.source === "payment") {
        this.setAddr(addr);
        this.$router.go(-1);
      }
    }
  },
  created() {
    getAddrList().then(res => {
      if (res.status === 200) {
        this.addrList = res.data.data;
      }
    });
  }
};
</script>

<style lang="less" scoped>
.container {
  .addr-list {
    .addr-cell {
      font-size: 0.64rem;
      color: #444444;
      margin-top: 0.48rem;
      background: #fff;
      padding-left: 3.4%;
      display: flex;
      justify-content: space-between;
      height: 4rem;

      .addr-info {
        width: 76%;

        .user {
          margin: 0.6rem 0 0.2rem;

          .tel {
            color: #999999;
            font-size: 0.56rem;
            margin-left: 0.48rem;
          }
        }

        .default {
          font-size: 0.56rem;
          color: #f85859;
          background: rgba(248, 88, 89, 0.2);
          border-radius: 0.12rem;
          padding: 0.05rem 0.24rem;
        }
      }

      .edit {
        width: 20%;
        border: none;
        background: none;
        font-size: 0.56rem;
        color: #999999;
        border-left: 1px solid rgba(233, 233, 233, 1);
        height: 1rem;
        margin-top: 1.5rem;
      }
    }
  }

  .bottom-btn {
    position: fixed;
    width: 100%;
    bottom: 0;
    left: 0;
    background: #0078ff;
    color: #fff;
    font-weight: bold;
    font-size: 0.64rem;
    line-height: 2rem;
    border: none;

    img {
      height: 0.88rem;
      width: 0.88rem;
      vertical-align: -8%;
    }
  }
  .fullscreen-margin{
    margin-bottom: 34px;
  }
}
</style>
